package com.tuanzi.loan.web.bean.settlement;

import com.google.common.collect.Lists;
import com.tuanzi.loan.business.service.settlement.SettlementPriceChangeRecordService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.vo.request.settlement.SettlementPriceChangeRecordRequest;
import com.tuanzi.loan.vo.response.settlement.SettlementPriceChangeRecordResponse;
import com.tuanzi.loan.web.configuration.JSFListingSessionBean;
import com.tuanzi.loan.web.lazy.settlement.SettlementPriceLazyDataModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.faces.bean.ViewScoped;
import java.util.List;

import static com.tuanzi.loan.business.constants.DictionaryCode.COOPERATION_MODE;

/**
 * @author caiwanlin
 * @create 2018-01-16 16:41
 */
@Data
@Debug
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class SettlementPriceListBean extends JSFListingSessionBean<SettlementPriceChangeRecordRequest, SettlementPriceChangeRecordResponse> {

    @Autowired
    private SettlementPriceChangeRecordService settlementPriceChangeRecordService;

    @Override
    protected String page() {
        return "/views/settlement/data-update/settlement-price/settlement-price-list.xhtml";
    }

    @Override
    protected void initLazyDataModel() {
        $ = new SettlementPriceChangeRecordRequest();
        lazyDataModel = new SettlementPriceLazyDataModel($, session, settlementPriceChangeRecordService);
    }

    /**
     * 新增
     * @return
     */
    public String onAdd() {
        return redirect("/views/settlement/data-update/settlement-price/settlement-price-info.xhtml");
    }

    /**
     * 查看
     * @param id
     * @return
     */
    public String onSee(String id) {
        return redirect("/views/settlement/data-update/settlement-price/settlement-price-info.xhtml?id="+id);
    }

    /**
     * 重置
     */
    public void onReset() {
        initLazyDataModel();
    }

    @Override
    protected List<String> getDictionaryCodes() {
        return Lists.newArrayList(COOPERATION_MODE);
    }
}
